<?php
namespace Home\Controller;
use Think\Controller;
class ExcelController extends ComController {
	public function index() {
		$this->display();
	}

    public function upexcel(){
     if (! empty ( $_FILES ['file_stu'] ['name'] )) 
	 {
    $tmp_file = $_FILES ['file_stu'] ['tmp_name'];
    $file_types = explode ( ".", $_FILES ['file_stu'] ['name'] );
    $file_type = $file_types [count ( $file_types ) - 1];

     /*判别是不是.xls文件，判别是不是excel文件*/
     if (strtolower ( $file_type ) != "xls")              
     {
       $this->error ( '不是Excel文件，重新上传' );
     }

    /*设置上传路径*/
     $savePath = APP_PATH.'public/upfile/Excel/';

    /*以时间来命名上传的文件*/
     $str = date ( 'Ymdhis' ); 
     $file_name = $str . "." . $file_type;

     /*是否上传成功*/
     if (! copy ( $tmp_file, $savePath . $file_name )) 
      {
        $this->error ( '上传失败' );
      }
    }
	
	$data = D('Excel')->import( $savePath . $file_name );
	
	$res = array();  //声明数组
	
	//获取信息状态
	foreach($data as $i=>$val){
		$Excel = M("Excel");
		$rs = $Excel->field('res')->Table('erp_products_log')->where('products_id='.$val)->limit(1)->select();
		$res[]= array($val,$rs[0]['res']);
		}
		
	//$data1 = Array (Array( 1,2 ),Array ( 2,3));
	$res = D('Excel')->export($res,$str,"01");
	}
}
?>